package net.sangpil.classes.net
{
	import flash.net.NetConnection;
	import flash.net.Responder;
	
	public class AMFPHP extends Object
	{
		private static var _gateway_url:String;
		private static var _netconnection:NetConnection;
		
		public function AMFPHP()
		{
			super();
		}
		
		public static function send(serviceName:String, onResult:Function, onFault:Function, ...args:*):void
		{
			trace("AMFPHP.send(), service name :", serviceName);
			
			var responder:Responder = new Responder(onResult, onFault);
			var collectArgs:Array = new Array;
			collectArgs.push(serviceName);
			collectArgs.push(responder);
			
			for (var i:uint=0; i<args.length; i++)
			{
				collectArgs.push(args[i]);
			}
			
			var callFunction:Function = _netconnection.call;
			
			try{
				callFunction.apply(_netconnection,collectArgs);
			}catch (error:*)
			{
				trace('error occour : ', error);	
			}
		}
		
		public static function get gateway_url():String
		{
			return _gateway_url;
		}
		
		public static function set gateway_url(path:String):void
		{
			_gateway_url = path;
			
			if(_netconnection){_netconnection = null;}
			_netconnection = new NetConnection;
			
			try{
				_netconnection.connect(_gateway_url);
			}catch(error:*)
			{
				trace('error occour : ', error);	
			}
			
		}
		
	}
}